package com.bocloud.cmp.service.app.monitor;

import java.util.concurrent.Callable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bocloud.cmp.entity.app.resource.OpenshiftMonitor;
import com.bocloud.common.http.HttpClient;
import com.bocloud.common.model.BaseResult;
import com.bocloud.common.model.Result;
/**
 * @author Zaney
 * @data:2017年4月20日
 * @describe:第一次线程池任务
 */
public class AppSecondTask implements Callable<BaseResult<JSONArray>> {
	private static Logger logger = LoggerFactory.getLogger(AppSecondTask.class);
	private OpenshiftMonitor monitor;
	@Autowired
	private AppSecondClient appSecondClient;

	public AppSecondTask(OpenshiftMonitor monitor) {
		super();
		this.monitor = monitor;
		appSecondClient = new AppSecondClient();
		HttpClient httpClient = new HttpClient();
		httpClient.setTimeout(6*10*1000);
		appSecondClient.setHttpClient(httpClient);
	}



	@Override
	public BaseResult<JSONArray> call() throws Exception {
		BaseResult<JSONArray> baseResult = new BaseResult<JSONArray>();
		Result monitorMessage = appSecondClient.url(monitor);
		if (monitorMessage.isFailed()) {
			baseResult.setData(null);
			baseResult.setSuccess(false);
			logger.error("监控数据未获取到: "+monitorMessage);
			return baseResult;
		}
		JSONArray array = JSONObject.parseArray(monitorMessage.getMessage());
		baseResult.setData(array);
		baseResult.setSuccess(true);
		return baseResult;
	}
	
}
